// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.ui;

import zombie.characters.IsoGameCharacter;
import zombie.characters.IsoPlayer;
import zombie.characters.BodyDamage.BodyDamage;
import zombie.characters.BodyDamage.BodyPartType;
import zombie.core.Color;
import zombie.core.textures.Texture;
import zombie.network.GameClient;

public final class UI_BodyPart extends UIElement {
    public float alpha = 1.0F;
    public final Color color = new Color(1.0F, 1.0F, 1.0F, 1.0F);
    public BodyPartType BodyPartType;
    public boolean IsFlipped = false;
    public float MaxOscilatorRate = 0.58F;
    public float MinOscilatorRate = 0.025F;
    public float Oscilator = 0.0F;
    public float OscilatorRate = 0.02F;
    public float OscilatorStep = 0.0F;
    IsoGameCharacter chr;
    boolean mouseOver = false;
    Texture scratchTex;
    Texture bandageTex;
    Texture dirtyBandageTex;
    Texture infectionTex;
    Texture deepWoundTex;
    Texture stitchTex;
    Texture biteTex;
    Texture glassTex;
    Texture boneTex;
    Texture splintTex;
    Texture burnTex;
    Texture bulletTex;

    public UI_BodyPart(BodyPartType type, int x, int y, String part, IsoGameCharacter character, boolean RenderFlipped) {
        String string = "male";
        if (character.isFemale()) {
            string = "female";
        }

        this.chr = character;
        this.BodyPartType = type;
        this.scratchTex = Texture.getSharedTexture("media/ui/BodyDamage/" + string + "_scratch_" + part);
        this.bandageTex = Texture.getSharedTexture("media/ui/BodyDamage/" + string + "_bandage_" + part);
        this.dirtyBandageTex = Texture.getSharedTexture("media/ui/BodyDamage/" + string + "_bandagedirty_" + part);
        this.infectionTex = Texture.getSharedTexture("media/ui/BodyDamage/" + string + "_infection_" + part);
        this.biteTex = Texture.getSharedTexture("media/ui/BodyDamage/" + string + "_bite_" + part);
        this.deepWoundTex = Texture.getSharedTexture("media/ui/BodyDamage/" + string + "_deepwound_" + part);
        this.stitchTex = Texture.getSharedTexture("media/ui/BodyDamage/" + string + "_stitches_" + part);
        this.glassTex = Texture.getSharedTexture("media/ui/BodyDamage/" + string + "_glass_" + part);
        this.boneTex = Texture.getSharedTexture("media/ui/BodyDamage/" + string + "_bones_" + part);
        this.splintTex = Texture.getSharedTexture("media/ui/BodyDamage/" + string + "_splint_" + part);
        this.burnTex = Texture.getSharedTexture("media/ui/BodyDamage/" + string + "_burn_" + part);
        this.bulletTex = Texture.getSharedTexture("media/ui/BodyDamage/" + string + "_bullet_" + part);
        this.x = (double)x;
        this.y = (double)y;
        this.width = (float)this.scratchTex.getWidth();
        this.height = (float)this.scratchTex.getHeight();
        this.IsFlipped = RenderFlipped;
    }

    @Override
    public void onMouseMoveOutside(double dx, double dy) {
        this.mouseOver = false;
    }

    @Override
    public void render() {
        BodyDamage bodyDamage = this.chr.getBodyDamage();
        if (GameClient.bClient && this.chr instanceof IsoPlayer && !((IsoPlayer)this.chr).isLocalPlayer()) {
            bodyDamage = this.chr.getBodyDamageRemote();
        }

        if (this.infectionTex != null && !bodyDamage.IsBandaged(this.BodyPartType) && bodyDamage.getBodyPart(this.BodyPartType).getWoundInfectionLevel() > 0.0F
            )
         {
            this.DrawTexture(this.infectionTex, 0.0, 0.0, (double)(bodyDamage.getBodyPart(this.BodyPartType).getWoundInfectionLevel() / 10.0F));
        }

        if (this.bandageTex != null && bodyDamage.IsBandaged(this.BodyPartType) && bodyDamage.getBodyPart(this.BodyPartType).getBandageLife() > 0.0F) {
            this.DrawTexture(this.bandageTex, 0.0, 0.0, 1.0);
        } else if (this.dirtyBandageTex != null
            && bodyDamage.IsBandaged(this.BodyPartType)
            && bodyDamage.getBodyPart(this.BodyPartType).getBandageLife() <= 0.0F) {
            this.DrawTexture(this.dirtyBandageTex, 0.0, 0.0, 1.0);
        } else if (this.scratchTex != null && bodyDamage.IsScratched(this.BodyPartType)) {
            this.DrawTexture(this.scratchTex, 0.0, 0.0, (double)(bodyDamage.getBodyPart(this.BodyPartType).getScratchTime() / 20.0F));
        } else if (this.scratchTex != null && bodyDamage.IsCut(this.BodyPartType)) {
            this.DrawTexture(this.scratchTex, 0.0, 0.0, (double)(bodyDamage.getBodyPart(this.BodyPartType).getCutTime() / 20.0F));
        } else if (this.biteTex != null
            && !bodyDamage.IsBandaged(this.BodyPartType)
            && bodyDamage.IsBitten(this.BodyPartType)
            && bodyDamage.getBodyPart(this.BodyPartType).getBiteTime() >= 0.0F) {
            this.DrawTexture(this.biteTex, 0.0, 0.0, 1.0);
        } else if (this.deepWoundTex != null && bodyDamage.IsDeepWounded(this.BodyPartType)) {
            this.DrawTexture(this.deepWoundTex, 0.0, 0.0, (double)(bodyDamage.getBodyPart(this.BodyPartType).getDeepWoundTime() / 15.0F));
        } else if (this.stitchTex != null && bodyDamage.IsStitched(this.BodyPartType)) {
            this.DrawTexture(this.stitchTex, 0.0, 0.0, 1.0);
        }

        if (this.boneTex != null
            && bodyDamage.getBodyPart(this.BodyPartType).getFractureTime() > 0.0F
            && bodyDamage.getBodyPart(this.BodyPartType).getSplintFactor() == 0.0F) {
            this.DrawTexture(this.boneTex, 0.0, 0.0, 1.0);
        } else if (this.splintTex != null && bodyDamage.getBodyPart(this.BodyPartType).getSplintFactor() > 0.0F) {
            this.DrawTexture(this.splintTex, 0.0, 0.0, 1.0);
        }

        if (this.glassTex != null && bodyDamage.getBodyPart(this.BodyPartType).haveGlass() && !bodyDamage.getBodyPart(this.BodyPartType).bandaged()) {
            this.DrawTexture(this.glassTex, 0.0, 0.0, 1.0);
        }

        if (this.bulletTex != null && bodyDamage.getBodyPart(this.BodyPartType).haveBullet() && !bodyDamage.getBodyPart(this.BodyPartType).bandaged()) {
            this.DrawTexture(this.bulletTex, 0.0, 0.0, 1.0);
        }

        if (this.burnTex != null && bodyDamage.getBodyPart(this.BodyPartType).getBurnTime() > 0.0F && !bodyDamage.getBodyPart(this.BodyPartType).bandaged()) {
            this.DrawTexture(this.burnTex, 0.0, 0.0, (double)(bodyDamage.getBodyPart(this.BodyPartType).getBurnTime() / 100.0F));
        }

        super.render();
    }
}
